#include "poissonnode.h"
#include "math.h"

PoissonNode::PoissonNode(double val):
        Node(val)
{
    lambdaNode = -1;    
}

PoissonNode::PoissonNode(QString lbl, double val, double sd, Node * lambdaNode, bool observed):
        Node(lbl, val, sd, observed)
{
    setLambdaNode(lambdaNode);    
}

bool PoissonNode::inRange(double v)
{
    return v >= 0.0;
}

double PoissonNode::generateSampleFromDistribution()
{
    // get rounded sample
    return (int)(Node::generateSampleFromDistribution() + 0.5);
}

void PoissonNode::setLambdaNode(Node * node)
{
    lambdaNode = addParentNode(node);
}

double PoissonNode::computeLogLikelihood()
{    
    return VALID_LOG(gsl_ran_poisson_pdf(this->getValue(),
                                   parents->at(lambdaNode)->getValue())
                    );
}

